package com.ruoyi.business.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.domain.bo.TCourseResourceBo;
import com.ruoyi.business.domain.vo.TCourseResourceVo;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.TCourseResourceMapper;
import com.ruoyi.business.domain.TCourseResource;
import com.ruoyi.business.service.ITCourseResourceService;

/**
 * CourseResourceService业务层处理
 * 
 * @author 最爱喝兽奶
 * @date 2024-03-20
 */
@SuppressWarnings("ALL")
@Service
public class TCourseResourceServiceImpl extends ServiceImpl<TCourseResourceMapper, TCourseResource> implements ITCourseResourceService
{
    @Autowired
    private TCourseResourceMapper tCourseResourceMapper;

    /**
     * 查询CourseResource
     * 
     * @param id CourseResource主键
     * @return CourseResource
     */
    @Override
    public TCourseResource selectTCourseResourceById(Long id)
    {
        return tCourseResourceMapper.selectTCourseResourceById(id);
    }

    /**
     * 查询CourseResource列表
     * 
     * @param tCourseResource CourseResource
     * @return CourseResource
     */
    @Override
    public List<TCourseResourceVo> selectTCourseResourceList(TCourseResourceBo bo)
    {
        TCourseResource courseResource = new TCourseResource();
        BeanUtils.copyProperties(bo, courseResource);
        List<TCourseResource> resources = tCourseResourceMapper.selectTCourseResourceList(courseResource);
        return resources.stream().map(item -> {
            TCourseResourceVo vo = new TCourseResourceVo();
            BeanUtils.copyProperties(item, vo);
            return vo;
        }).collect(Collectors.toList());
    }

    /**
     * 新增CourseResource
     * 
     * @param tCourseResource CourseResource
     * @return 结果
     */
    @Override
    public int insertTCourseResource(TCourseResource tCourseResource)
    {
        tCourseResource.setCreateTime(System.currentTimeMillis());
        return tCourseResourceMapper.insertTCourseResource(tCourseResource);
    }

    /**
     * 修改CourseResource
     * 
     * @param tCourseResource CourseResource
     * @return 结果
     */
    @Override
    public int updateTCourseResource(TCourseResource tCourseResource)
    {
        tCourseResource.setUpdateTime(System.currentTimeMillis());
        return tCourseResourceMapper.updateTCourseResource(tCourseResource);
    }

    /**
     * 批量删除CourseResource
     * 
     * @param ids 需要删除的CourseResource主键
     * @return 结果
     */
    @Override
    public int deleteTCourseResourceByIds(Long[] ids)
    {
        return tCourseResourceMapper.deleteTCourseResourceByIds(ids);
    }

    /**
     * 删除CourseResource信息
     * 
     * @param id CourseResource主键
     * @return 结果
     */
    @Override
    public int deleteTCourseResourceById(Long id)
    {
        return tCourseResourceMapper.deleteTCourseResourceById(id);
    }

    @Override
    public synchronized void addDownloadNum(Long id) {
        if (null == id) {
            return;
        }
        baseMapper.addDownloadNum(id);
    }
}
